/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RemoteDesktop;

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;

/**
 *
 * @author Oho
 */
public class ThreadImages extends Thread {

    //JDesktopPane desktop;
   // Socket sk;
    ObjectInputStream inp = null;
   // Rectangle rt;
//    private JPanel pn = null;
    private JPanel cPanel = new JPanel();
 

    public ThreadImages(ObjectInputStream inp, JDesktopPane desktop, JPanel pn) {
        this.inp = inp;
       //this.desktop = desktop;
        this.cPanel = pn;
    }

    ThreadImages(ObjectInputStream inp, JPanel cPanel) {
        this.inp= inp;
        this.cPanel = cPanel;
    }


    public void ThreadRead() {
        try {
            ImageIcon icon = (ImageIcon) inp.readObject();
            Image img = icon.getImage();
            img = img.getScaledInstance(cPanel.getWidth(), cPanel.getHeight(), Image.SCALE_FAST);
            Graphics graphics = cPanel.getGraphics();
            graphics.drawImage(img, 0, 0, cPanel.getWidth(), cPanel.getHeight(), cPanel);

        } catch (IOException ex) {
            Logger.getLogger(ThreadImages.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ThreadImages.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void run() {
        //try {
//        drawGUI();
        while (true) {
            ThreadRead();
        }

    }
}
